# Figure A13 and A14 Script ####

rm(list=ls());gc();gc();gc();gc();gc();gc();gc();gc()


library(dplyr)
library(lubridate)     
library(zoo)           
library(ineq)
library(Matrix)
library(reshape2)
library(tm)
library(tidyverse)
library(data.table)
library(glmnet)

here::i_am("Scripts/FigA13A14Script.R")

library(here)

# Figure A13 ####
#Start with predicting 2012 Federal Donations

#Load State data
kycomp<-readRDS(here("Data", "KYpredictdata.rds"))
micomp<-readRDS(here("Data", "MIpredictdata.rds"))
ohcomp<-readRDS(here("Data", "OHpredictdata.rds"))

#Load 2012 Federal Data
kys<-readRDS(here("Data", "FECpredictdata2012.rds"))

kys<-kys[kys$party3!="OTHER",]

#Linear Probability Model, first by state
#OH
ohcomp$fundraisernum<-as.numeric(as.character(ohcomp$fundraiser))

predictfedoh20112012lm<-lm(fundraisernum~weekday+cINCUMBENCYSTATUS+daypercsameamt+biground+biground2+dayperc+v_ntl+v2_ntl+v3_ntl+v+v2+v3+vunw+v2unw+v3unw+v4_ntl+v5_ntl+v6_ntl+v4+v5+v6+v4unw+v4unw+v6unw+vnorm_ntl+vnorm2_ntl+vnorm3_ntl+vnorm4_ntl+vnorm5_ntl+vnorm6_ntl+numsamedaydons+numsamedaysameamt+party3, data=ohcomp)


fedpreds<-predict(predictfedoh20112012lm,kys, se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys$lmfit2012oh<-fedpreds$fit
kys$lmfit2012seoh<-fedpreds$se.fit


#Very simple logistic regression predicting fundraising event:

predictfedoh20112012log<-glm(fundraiser~weekday+cINCUMBENCYSTATUS+daypercsameamt+biground+biground2+dayperc+v_ntl+v2_ntl+v3_ntl+v+v2+v3+vunw+v2unw+v3unw+v4_ntl+v5_ntl+v6_ntl+v4+v5+v6+v4unw+v4unw+v6unw+vnorm_ntl+vnorm2_ntl+vnorm3_ntl+vnorm4_ntl+vnorm5_ntl+vnorm6_ntl+numsamedaydons+numsamedaysameamt+party3, family="binomial",data=ohcomp)

fedpreds<-predict(predictfedoh20112012log,kys,type="response", se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys$logfit2012oh<-fedpreds$fit
kys$logfit2012seoh<-fedpreds$se.fit





#KY next
#kycomp<-kycomp[complete.cases(kycomp),]

#Linear probability model

kycomp$fundraisernum<-as.numeric(as.character(kycomp$fundraiser))

predictfedky20112012lm<-lm(fundraisernum~weekday+cINCUMBENCYSTATUS+daypercsameamt+biground+biground2+dayperc+v_ntl+v2_ntl+v3_ntl+v+v2+v3+vunw+v2unw+v3unw+v4_ntl+v5_ntl+v6_ntl+v4+v5+v6+v4unw+v4unw+v6unw+vnorm_ntl+vnorm2_ntl+vnorm3_ntl+vnorm4_ntl+vnorm5_ntl+vnorm6_ntl+numsamedaydons+numsamedaysameamt+party3, data=kycomp)

summary(predictfedky20112012lm)

fedpreds<-predict(predictfedky20112012lm,kys, se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys$lmfit2012ky<-fedpreds$fit
kys$lmfit2012seky<-fedpreds$se.fit




#Very simple logistic regression predicting fundraising event:

predictfedky20112012log<-glm(fundraiser~weekday+cINCUMBENCYSTATUS+daypercsameamt+biground+biground2+dayperc+v_ntl+v2_ntl+v3_ntl+v+v2+v3+vunw+v2unw+v3unw+v4_ntl+v5_ntl+v6_ntl+v4+v5+v6+v4unw+v4unw+v6unw+vnorm_ntl+vnorm2_ntl+vnorm3_ntl+vnorm4_ntl+vnorm5_ntl+vnorm6_ntl+numsamedaydons+numsamedaysameamt+party3, family="binomial",data=kycomp)

fedpreds<-predict(predictfedky20112012log,kys,type="response", se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys$logfit2012ky<-fedpreds$fit
kys$logfit2012seky<-fedpreds$se.fit




#Now MIchigan

#micomp<-micomp[complete.cases(micomp),]

#Linear probability model

micomp$fundraisernum<-as.numeric(as.character(micomp$fundraiser))

predictfedmi20112012lm<-lm(fundraisernum~weekday+cINCUMBENCYSTATUS+daypercsameamt+biground+biground2+dayperc+v_ntl+v2_ntl+v3_ntl+v+v2+v3+vunw+v2unw+v3unw+v4_ntl+v5_ntl+v6_ntl+v4+v5+v6+v4unw+v4unw+v6unw+vnorm_ntl+vnorm2_ntl+vnorm3_ntl+vnorm4_ntl+vnorm5_ntl+vnorm6_ntl+numsamedaydons+numsamedaysameamt+party3, data=micomp)

summary(predictfedmi20112012lm)

fedpreds<-predict(predictfedmi20112012lm,kys, se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys$lmfit2012mi<-fedpreds$fit
kys$lmfit2012semi<-fedpreds$se.fit





#Very simple logistic regression predicting fundraising event:

predictfedmi20112012log<-glm(fundraiser~weekday+cINCUMBENCYSTATUS+daypercsameamt+biground+biground2+dayperc+v_ntl+v2_ntl+v3_ntl+v+v2+v3+vunw+v2unw+v3unw+v4_ntl+v5_ntl+v6_ntl+v4+v5+v6+v4unw+v4unw+v6unw+vnorm_ntl+vnorm2_ntl+vnorm3_ntl+vnorm4_ntl+vnorm5_ntl+vnorm6_ntl+numsamedaydons+numsamedaysameamt+party3, family="binomial",data=micomp)

fedpreds<-predict(predictfedmi20112012log,kys,type="response", se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys$logfit2012mi<-fedpreds$fit
kys$logfit2012semi<-fedpreds$se.fit





#NOw add all three together and run the same code
allcomp<-bind_rows(kycomp,ohcomp,micomp)



#Linear probability model

allcomp$fundraisernum<-as.numeric(as.character(allcomp$fundraiser))

predictfedall20112012lm<-lm(fundraisernum~weekday+cINCUMBENCYSTATUS+daypercsameamt+biground+biground2+dayperc+v_ntl+v2_ntl+v3_ntl+v+v2+v3+vunw+v2unw+v3unw+v4_ntl+v5_ntl+v6_ntl+v4+v5+v6+v4unw+v4unw+v6unw+vnorm_ntl+vnorm2_ntl+vnorm3_ntl+vnorm4_ntl+vnorm5_ntl+vnorm6_ntl+numsamedaydons+numsamedaysameamt+party3, data=allcomp)

summary(predictfedall20112012lm)

fedpreds<-predict(predictfedall20112012lm,kys, se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys$lmfit2012all<-fedpreds$fit
kys$lmfit2012seall<-fedpreds$se.fit



#Very simple logistic regression predicting fundraising event:

predictfedall20112012log<-glm(fundraiser~weekday+cINCUMBENCYSTATUS+daypercsameamt+biground+biground2+dayperc+v_ntl+v2_ntl+v3_ntl+v+v2+v3+vunw+v2unw+v3unw+v4_ntl+v5_ntl+v6_ntl+v4+v5+v6+v4unw+v4unw+v6unw+vnorm_ntl+vnorm2_ntl+vnorm3_ntl+vnorm4_ntl+vnorm5_ntl+vnorm6_ntl+numsamedaydons+numsamedaysameamt+party3, family="binomial",data=allcomp)

fedpreds<-predict(predictfedall20112012log,kys,type="response", se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys$logfit2012all<-fedpreds$fit
kys$logfit2012seall<-fedpreds$se.fit

#Predict 2016, and 2014
#2016
kys16<-readRDS(here("Data", "FECpredictdata2016.rds"))

kys16<-kys16[kys16$party3!="OTHER",]

fedpreds<-predict(predictfedoh20112012lm,kys16, se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys16$lmfit2016oh<-fedpreds$fit
kys16$lmfit2016seoh<-fedpreds$se.fit


#Very simple logistic regression predicting fundraising event:

fedpreds<-predict(predictfedoh20112012log,kys16,type="response", se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys16$logfit2016oh<-fedpreds$fit
kys16$logfit2016seoh<-fedpreds$se.fit





#KY next
#kycomp<-kycomp[complete.cases(kycomp),]

#Linear probability model


fedpreds<-predict(predictfedky20112012lm,kys16, se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys16$lmfit2016ky<-fedpreds$fit
kys16$lmfit2016seky<-fedpreds$se.fit




#Very simple logistic regression predicting fundraising event:


fedpreds<-predict(predictfedky20112012log,kys16,type="response", se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys16$logfit2016ky<-fedpreds$fit
kys16$logfit2016seky<-fedpreds$se.fit




#Now MIchigan

#micomp<-micomp[complete.cases(micomp),]

#Linear probability model


fedpreds<-predict(predictfedmi20112012lm,kys16, se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys16$lmfit2016mi<-fedpreds$fit
kys16$lmfit2016semi<-fedpreds$se.fit


#Very simple logistic regression predicting fundraising event:

fedpreds<-predict(predictfedmi20112012log,kys16,type="response", se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys16$logfit2016mi<-fedpreds$fit
kys16$logfit2016semi<-fedpreds$se.fit



fedpreds<-predict(predictfedall20112012lm,kys16, se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys16$lmfit2016all<-fedpreds$fit
kys16$lmfit2016seall<-fedpreds$se.fit



fedpreds<-predict(predictfedall20112012log,kys16,type="response", se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys16$logfit2016all<-fedpreds$fit
kys16$logfit2016seall<-fedpreds$se.fit




#2014

kys14<-readRDS(here("Data", "FECpredictdata2014.rds"))

kys14<-kys14[kys14$party3!="OTHER",]

fedpreds<-predict(predictfedoh20112012lm,kys14, se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys14$lmfit2014oh<-fedpreds$fit
kys14$lmfit2014seoh<-fedpreds$se.fit


#Very simple logistic regression predicting fundraising event:

fedpreds<-predict(predictfedoh20112012log,kys14,type="response", se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys14$logfit2014oh<-fedpreds$fit
kys14$logfit2014seoh<-fedpreds$se.fit





#KY next
#kycomp<-kycomp[complete.cases(kycomp),]

#Linear probability model


fedpreds<-predict(predictfedky20112012lm,kys14, se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys14$lmfit2014ky<-fedpreds$fit
kys14$lmfit2014seky<-fedpreds$se.fit




#Very simple logistic regression predicting fundraising event:


fedpreds<-predict(predictfedky20112012log,kys14,type="response", se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys14$logfit2014ky<-fedpreds$fit
kys14$logfit2014seky<-fedpreds$se.fit




#Now MIchigan

#micomp<-micomp[complete.cases(micomp),]

#Linear probability model


fedpreds<-predict(predictfedmi20112012lm,kys14, se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys14$lmfit2014mi<-fedpreds$fit
kys14$lmfit2014semi<-fedpreds$se.fit


#Very simple logistic regression predicting fundraising event:

fedpreds<-predict(predictfedmi20112012log,kys14,type="response", se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys14$logfit2014mi<-fedpreds$fit
kys14$logfit2014semi<-fedpreds$se.fit



fedpreds<-predict(predictfedall20112012lm,kys14, se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys14$lmfit2014all<-fedpreds$fit
kys14$lmfit2014seall<-fedpreds$se.fit



fedpreds<-predict(predictfedall20112012log,kys14,type="response", se.fit = TRUE)

#attach the fed predictions to the main data set for graphing
kys14$logfit2014all<-fedpreds$fit
kys14$logfit2014seall<-fedpreds$se.fit

kys$fundraiseramount<-kys$logfit2012all*kys$AMOUNT
kys$nonfundraiseramount<-(1-kys$logfit2012all)*kys$AMOUNT
kys$fundraiseramountky<-kys$logfit2012ky*kys$AMOUNT
kys$nonfundraiseramountky<-(1-kys$logfit2012ky)*kys$AMOUNT
kys$fundraiseramountoh<-kys$logfit2012oh*kys$AMOUNT
kys$nonfundraiseramountoh<-(1-kys$logfit2012oh)*kys$AMOUNT
kys$fundraiseramountmi<-kys$logfit2012mi*kys$AMOUNT
kys$nonfundraiseramountmi<-(1-kys$logfit2012mi)*kys$AMOUNT

kys14$fundraiseramount<-kys14$logfit2014all*kys14$AMOUNT
kys14$nonfundraiseramount<-(1-kys14$logfit2014all)*kys14$AMOUNT
kys14$fundraiseramountky<-kys14$logfit2014ky*kys14$AMOUNT
kys14$nonfundraiseramountky<-(1-kys14$logfit2014ky)*kys14$AMOUNT
kys14$fundraiseramountoh<-kys14$logfit2014oh*kys14$AMOUNT
kys14$nonfundraiseramountoh<-(1-kys14$logfit2014oh)*kys14$AMOUNT
kys14$fundraiseramountmi<-kys14$logfit2014mi*kys14$AMOUNT
kys14$nonfundraiseramountmi<-(1-kys14$logfit2014mi)*kys14$AMOUNT

kys16$fundraiseramount<-kys16$logfit2016all*kys16$AMOUNT
kys16$nonfundraiseramount<-(1-kys16$logfit2016all)*kys16$AMOUNT
kys16$fundraiseramountky<-kys16$logfit2016ky*kys16$AMOUNT
kys16$nonfundraiseramountky<-(1-kys16$logfit2016ky)*kys16$AMOUNT
kys16$fundraiseramountoh<-kys16$logfit2016oh*kys16$AMOUNT
kys16$nonfundraiseramountoh<-(1-kys16$logfit2016oh)*kys16$AMOUNT
kys16$fundraiseramountmi<-kys16$logfit2016mi*kys16$AMOUNT
kys16$nonfundraiseramountmi<-(1-kys16$logfit2016mi)*kys16$AMOUNT

#only logs
aggmonth<-kys %>%
  group_by(month, year)%>%
  dplyr::summarize(totalevent=sum(fundraiseramount, na.rm=T),
            totalnonevent=sum(nonfundraiseramount, na.rm=T),
            totaleventoh=sum(fundraiseramountoh, na.rm=T),
            totalnoneventoh=sum(nonfundraiseramountoh, na.rm=T),
            totaleventky=sum(fundraiseramountky, na.rm=T),
            totalnoneventky=sum(nonfundraiseramountky, na.rm=T),
            totaleventmi=sum(fundraiseramountmi, na.rm=T),
            totalnoneventmi=sum(nonfundraiseramountmi, na.rm=T))

aggmonth$perceventfundraiserall<-aggmonth$totalevent/(aggmonth$totalevent+aggmonth$totalnonevent)
aggmonth$perceventfundraisermi<-aggmonth$totaleventmi/(aggmonth$totaleventmi+aggmonth$totalnoneventmi)
aggmonth$perceventfundraiserky<-aggmonth$totaleventky/(aggmonth$totaleventky+aggmonth$totalnoneventky)
aggmonth$perceventfundraiseroh<-aggmonth$totaleventoh/(aggmonth$totaleventoh+aggmonth$totalnoneventoh)



aggpiv<-pivot_longer(aggmonth, perceventfundraiserall:perceventfundraiseroh, names_to = "state", names_prefix = "percevent", values_to = "percentage")



aggmonth<-aggpiv%>%
  filter(year %in% c("2011", '2012'))


aggmonth14<-kys14 %>%
  group_by(month, year)%>%
  dplyr::summarize(totalevent=sum(fundraiseramount, na.rm=T),
            totalnonevent=sum(nonfundraiseramount, na.rm=T),
            totaleventoh=sum(fundraiseramountoh, na.rm=T),
            totalnoneventoh=sum(nonfundraiseramountoh, na.rm=T),
            totaleventky=sum(fundraiseramountky, na.rm=T),
            totalnoneventky=sum(nonfundraiseramountky, na.rm=T),
            totaleventmi=sum(fundraiseramountmi, na.rm=T),
            totalnoneventmi=sum(nonfundraiseramountmi, na.rm=T))

aggmonth14$perceventfundraiserall<-aggmonth14$totalevent/(aggmonth14$totalevent+aggmonth14$totalnonevent)
aggmonth14$perceventfundraisermi<-aggmonth14$totaleventmi/(aggmonth14$totaleventmi+aggmonth14$totalnoneventmi)
aggmonth14$perceventfundraiserky<-aggmonth14$totaleventky/(aggmonth14$totaleventky+aggmonth14$totalnoneventky)
aggmonth14$perceventfundraiseroh<-aggmonth14$totaleventoh/(aggmonth14$totaleventoh+aggmonth14$totalnoneventoh)



aggpiv<-pivot_longer(aggmonth14, perceventfundraiserall:perceventfundraiseroh, names_to = "state", names_prefix = "percevent", values_to = "percentage")



aggmonth14<-aggpiv%>%
  filter(year %in% c("2013", '2014'))


aggmonth16<-kys16 %>%
  group_by(month, year)%>%
  dplyr::summarize(totalevent=sum(fundraiseramount, na.rm=T),
            totalnonevent=sum(nonfundraiseramount, na.rm=T),
            totaleventoh=sum(fundraiseramountoh, na.rm=T),
            totalnoneventoh=sum(nonfundraiseramountoh, na.rm=T),
            totaleventky=sum(fundraiseramountky, na.rm=T),
            totalnoneventky=sum(nonfundraiseramountky, na.rm=T),
            totaleventmi=sum(fundraiseramountmi, na.rm=T),
            totalnoneventmi=sum(nonfundraiseramountmi, na.rm=T))

aggmonth16$perceventfundraiserall<-aggmonth16$totalevent/(aggmonth16$totalevent+aggmonth16$totalnonevent)
aggmonth16$perceventfundraisermi<-aggmonth16$totaleventmi/(aggmonth16$totaleventmi+aggmonth16$totalnoneventmi)
aggmonth16$perceventfundraiserky<-aggmonth16$totaleventky/(aggmonth16$totaleventky+aggmonth16$totalnoneventky)
aggmonth16$perceventfundraiseroh<-aggmonth16$totaleventoh/(aggmonth16$totaleventoh+aggmonth16$totalnoneventoh)



aggpiv<-pivot_longer(aggmonth16, perceventfundraiserall:perceventfundraiseroh, names_to = "state", names_prefix = "percevent", values_to = "percentage")




aggmonth16<-aggpiv%>%
  filter(year %in% c("2015", '2016'))

aggmonth16$electioncycle<-"elec2016"
aggmonth14$electioncycle<-"elec2014"
aggmonth$electioncycle<-"elec2012"

#Now let's do a graph starting at 100% of event reliance in 
#January of year before election

#Get the top four values (the january -1 values for each of the states)
aggmonth16$base<-rep(aggmonth16$percentage[1:4], 24)
aggmonth14$base<-rep(aggmonth14$percentage[1:4], 24)
aggmonth$base<-rep(aggmonth$percentage[1:4], 24)

#Now get the percentage of that base each level is

aggmonth16$ratio<-aggmonth16$percentage/aggmonth16$base
aggmonth14$ratio<-aggmonth14$percentage/aggmonth14$base
aggmonth$ratio<-aggmonth$percentage/aggmonth$base


#Now let's try graphing

#bring together
aggs<-rbind(aggmonth, aggmonth14, aggmonth16)



#Remove election year months
aggs$novdecelecyear<-ifelse(format(aggs$month, "%m") %in% c(11,12) & aggs$year %in% c(2014,2016, 2012), 1, 0)

aggs2<-aggs[aggs$novdecelecyear==0,]

#Same Graph but with bigger axes for presentations
percplotalllog<-aggs2%>%
  ggplot(aes(x=month, y=ratio, color=state))+
  geom_line(aes(group=interaction(electioncycle, state)))+
  scale_x_date(date_breaks = "6 months" , date_labels = "%b-%y",limits = as.Date(c("2011-01-01", "2016-10-31")))+
  theme_bw()+ 
  scale_y_continuous(labels = scales::percent, limits=c(.45,1.2))+
  xlab("Month")+
  ylab("Predicted % of First Month \n Fundraiser Reliance")+
  scale_color_discrete(name = "Predicting Sample", labels = c("All Combined", "KY", "MI","OH"))+ 
  geom_hline(yintercept=1, linetype="dashed", color = "red")+
  theme(legend.position="bottom")+
  theme(axis.text=element_text(size=15))+
  theme(legend.text=element_text(size=18))+
  theme(axis.title=element_text(size=18))+
  theme(legend.title=element_text(size=18))


percplotalllog

ggsave(here("Results", "FigA13.pdf"),width = 12, height = 5)




#Use the "ALL" prediction that charts the level of 
#amounts in each group over the cycle


aggmonth<-kys %>%
  group_by(month, year)%>%
  dplyr::summarize(totalevent=log(sum(fundraiseramount, na.rm=T)),
            totalnonevent=log(sum(nonfundraiseramount, na.rm=T)))


aggpiv<-pivot_longer(aggmonth, totalevent:totalnonevent, names_to = "type", names_prefix = "total", values_to = "logsum")



aggmonth<-aggpiv%>%
  filter(year %in% c("2011", '2012'))



aggmonth14<-kys14 %>%
  group_by(month, year)%>%
  dplyr::summarize(totalevent=log(sum(fundraiseramount, na.rm=T)),
            totalnonevent=log(sum(nonfundraiseramount, na.rm=T)))


aggpiv<-pivot_longer(aggmonth14, totalevent:totalnonevent, names_to = "type", names_prefix = "total", values_to = "logsum")



aggmonth14<-aggpiv%>%
  filter(year %in% c("2013", '2014'))


aggmonth16<-kys16 %>%
  group_by(month, year)%>%
  dplyr::summarize(totalevent=log(sum(fundraiseramount, na.rm=T)),
            totalnonevent=log(sum(nonfundraiseramount, na.rm=T)))

aggpiv<-pivot_longer(aggmonth16, totalevent:totalnonevent, names_to = "type", names_prefix = "total", values_to = "logsum")



aggmonth16<-aggpiv%>%
  filter(year %in% c("2015", '2016'))

aggmonth16$electioncycle<-"elec2016"
aggmonth14$electioncycle<-"elec2014"
aggmonth$electioncycle<-"elec2012"

#bring together
aggs<-rbind(aggmonth, aggmonth14, aggmonth16)



#Remove election year months
aggs$novdecelecyear<-ifelse(format(aggs$month, "%m") %in% c(11,12) & aggs$year %in% c(2014,2016, 2012), 1, 0)

aggs2<-aggs[aggs$novdecelecyear==0,]

percplotalllog<-aggs2%>%
  ggplot(aes(x=month, y=logsum, color=type))+
  geom_line(aes(group=interaction(electioncycle, type)))+
  scale_x_date(date_breaks = "4 months" , date_labels = "%b-%y",limits = as.Date(c("2011-01-01", "2016-10-31")))+
  theme_bw()+ 
  scale_y_continuous(limits=c(14,18))+
  xlab("Month")+
  ylab("Predicted Log Sum of Amount Given")+
  scale_color_discrete(name = "Type of Donation", labels = c("Events", "Non-Events"))+
  theme(legend.position="bottom")

percplotalllog

ggsave(here("Results", "FigA14.pdf"),width = 12, height = 5)

